package jinyilw.swing.visuals.Icomp;

import java.awt.Component;

import javax.swing.Action;
import javax.swing.JMenu;

import jinyilw.swing.i18n.ICSetting;
import jinyilw.swing.i18n.LanguageChanger;

public class IMenu extends JMenu implements LanguageChanger
{
	private static final long serialVersionUID = 3844030456243595097L;
	protected ICSetting i18nSetting;

	public IMenu()
	{
	}

	public IMenu(String s)
	{
		super(s);
	}

	public IMenu(Action a)
	{
		super(a);
	}

	public IMenu(String s, boolean b)
	{
		super(s, b);
	}
	public IMenu(ICSetting iSetting)
	{
		setText(iSetting);
	}

	public IMenu(ICSetting iSetting, boolean b)
	{
		super("", b);
		setText(iSetting);
	}

	@Override
	public void changLanguage()
	{
		if (i18nSetting != null && i18nSetting.needChange())
		{
			setText(i18nSetting.getI18nString());
			if (i18nSetting.isFontChange())
				setFont(i18nSetting.getFont(this));
			for (Component c : getMenuComponents())
				if (c instanceof LanguageChanger)
					((LanguageChanger) c).changLanguage();
		}
	}

	@Override
	public void setICSetting(ICSetting iSetting)
	{
		i18nSetting = iSetting;
	}

	@Override
	public ICSetting getICSetting()
	{
		return i18nSetting;
	}

	@Override
	public void updateText(String text)
	{
		setText(text);
	}
}
